package com.wl.jetpackdemo.chat

import android.widget.TextView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.entity.MultiItemEntity
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.wl.jetpackdemo.R
import com.wl.jetpackdemo.base.Constant

/**
 *
 * Created by wangliang on 2021/2/20.
 */
class MessageAdapter : BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {

    constructor() {
        addItemType(Constant.UI_MESSAGE_TYPE_TEXT_SELF, R.layout.item_message_text_self)
        addItemType(Constant.UI_MESSAGE_TYPE_TEXT_OTHER, R.layout.item_message_text_other)
    }

    override fun convert(holder: BaseViewHolder, item: MultiItemEntity) {
        when(holder.itemViewType) {
            Constant.UI_MESSAGE_TYPE_TEXT_SELF, Constant.UI_MESSAGE_TYPE_TEXT_OTHER -> {
                val textMsg = item as TextMessageItem
                holder.getView<TextView>(R.id.msg_content).text = textMsg.content
            }
        }
    }
}